# 导入自动化模块
from selenium import webdriver
#时间模块
import time
#导入动作库
from selenium.webdriver import ActionChains
#导入请求模块
import requests

#声明类
class MyTest:
    def __init__(self):
        #声明浏览器实例
        self.browser = webdriver.Chrome('C:/Program Files/Google/Chrome/Application/chromedriver.exe')


    def get_url(self,url):
        #打开浏览器对象
        self.browser.get(url)
        #延迟
        time.sleep(1)

        self.browser.find_element_by_class_name('van-tab__text').click()
        #标签选择器
        self.browser.find_elements_by_tag_name('input')[1].send_keys('jch')
        self.browser.find_elements_by_tag_name('input')[2].send_keys('qweqwe123')


        #拖拽动作
        time.sleep(1)
        #地位拖拽球体
        ball = self.browser.find_element_by_class_name('dv_handler')
        #定义球体动作实例
        action = ActionChains(self.browser)
        #按住鼠标不抬起
        action.click_and_hold(ball).perform()
        #释放动作
        action.reset_actions()
        #移动位置
        action.move_by_offset(380,0).perform()

        time.sleep(1)
        # 登录按钮
        self.browser.find_elements_by_class_name('van-button')[0].click()

        time.sleep(1)

        #选择超链接
        self.browser.find_elements_by_tag_name('a')[1].click()
        time.sleep(1)




        #手机号


        res = requests.get("http://localhost:5000/user/sendmsg/",params={'phone':'18595604641'})
        res = res.json()
        code = res['code']

        # 填写表单

        self.browser.find_elements_by_tag_name('input')[1].send_keys('18595604641')
        self.browser.find_elements_by_tag_name('input')[2].send_keys(code)

        # 拖拽动作
        time.sleep(1)
        # 地位拖拽球体
        ball = self.browser.find_element_by_class_name('dv_handler')
        # 定义球体动作实例
        action = ActionChains(self.browser)
        # 按住鼠标不抬起
        action.click_and_hold(ball).perform()
        # 释放动作
        action.reset_actions()
        # 移动位置
        action.move_by_offset(380, 0).perform()

        time.sleep(1)
        # 登录按钮
        self.browser.find_element_by_class_name('van-button--normal').click()

        time.sleep(1)

        # 选择超链接
        self.browser.find_elements_by_tag_name('a')[1].click()

        time.sleep(2)







        #关闭
        self.browser.quit()

#实例化对象
mytest = MyTest()
mytest.get_url('http://localhost:8080/user_login')